package com.pw.study.arithmetic.task

import com.pw.study.arithmetic.stack.FutureStack

import scala.io.StdIn

/**
 * @Desc: 栈
 * @author: future
 * @since: 2022/5/30-20:37
 */
object StackTask {
  def main(args: Array[String]): Unit = {
    val stack: FutureStack = new FutureStack(4)
    var key = ""
    while (true) {
      println("show:表示显示栈")
      println("exit:表示退出程序")
      println("push:表示添加数据到栈")
      println("pop:表示从栈取出数据")

      stack.isFull()
      key = StdIn.readLine("请输出选择push|show|pop|exit: ")
      key match {
        case "show" => stack.list()
        case "push" => {
          println("请输入一个整数:")
          val value: Int = StdIn.readInt()
          stack.push(value)
        }
        case "pop" => {
          val res = stack.pop()
          if (res.isInstanceOf[Exception]) {
            println(res.asInstanceOf[Exception].getMessage)
          } else {
            println(s"取出的数为:$res ")
          }
        }
        case "exit" => {
          println("exit......")
          System.exit(0)
        }
      }

    }
  }
}
